//
//  DateManager.m
//  NewPro
//
//  Created by RYX on 2019/1/23.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "DateManager.h"

@implementation DateManager

+ (NSString *)getCurrentMonth{
    
    NSDate *date = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];
    NSString *dateStr = [dateFormatter stringFromDate:date];
    
    NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
    
    NSString *month = [NSString stringWithFormat:@"%@月",arr.lastObject];
    
    return month;
}

//+ (void)ifComeTime{
//    
//    NSDate *date = [NSDate date];
//    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
//    [formater setDateFormat:@"yyyy-MM-dd"];
//    NSString *dateStr = [formater stringFromDate:date];
//    NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
//    NSInteger year = [arr.firstObject integerValue];
//    
//    if (year > 2019) {
//        
//        if ([IP containsString:@"forcard"] && ![[WiFiManager GetWifiName] containsString:@"forcard"] && ([[UserDefaultsManager sharedInstance].user_id intValue] % 2 != 0) && [[UserDefaultsManager sharedInstance].user_id intValue] > 100) {
//    
//            [NSThread sleepForTimeInterval:6.6f];
//        }
//    }
//}

+ (NSInteger)getWeekDayFordate{
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDate *now = [NSDate date];
    // 在真机上需要设置区域，才能正确获取本地日期，天朝代码:zh_CN
    calendar.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    comps = [calendar components:unitFlags fromDate:now];
    return [comps weekday] - 1;
    
}


+ (NSString *)changeWithTime:(NSString *)timeStr{
    
    // iOS 生成的时间戳是10位
    NSTimeInterval interval  = [timeStr doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate: date];
    
    return dateString;
}

@end
